package com.lanlian.cayman.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.cayman.R;
import com.lanlian.cayman.utils.MResUtil;
import com.lanlian.commonlib.bean.FundDetailsInfo;
import com.lanlian.utillib.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 资金流水-盈亏Adapter
 *     version: 1.0
 * </pre>
 */
public class FundDetailsPnlAdapter extends BaseQuickAdapter<FundDetailsInfo, BaseViewHolder> {

    public FundDetailsPnlAdapter(int layoutResId, @Nullable List<FundDetailsInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FundDetailsInfo item) {
        helper.setBackgroundColor(R.id.lay_position, (helper.getLayoutPosition() + 1) % 2 == 0 ?
                mContext.getResources().getColor(R.color.color_bg_text_view_style2) :
                mContext.getResources().getColor(R.color.color_bg_text_view_style3));
        Date date = DateUtils.StringToDate(item.getlInputTime());
        String time = DateUtils.DateToString(date, "yyyy-MM-dd\nHH:mm:ss");
        helper.setText(R.id.tv_status, item.getcStatus());
        helper.setText(R.id.tv_time, time);
        helper.setText(R.id.tv_no, item.getlSerialId().toString());
        helper.setText(R.id.tv_base_currency, item.getSourceCurrency());
        helper.setText(R.id.tv_base_money, item.getSourceMoney().toString());
        if (item.getSourceMoney() > 0) {
            helper.setText(R.id.tv_base_money, String.format("+%.2f", item.getSourceMoney()));
            helper.setTextColor(R.id.tv_base_money, MResUtil.getUpColor());
        } else if (item.getSourceMoney() < 0) {
            helper.setText(R.id.tv_base_money, String.format("%.2f", item.getSourceMoney()));
            helper.setTextColor(R.id.tv_base_money, MResUtil.getDownColor());
        } else {
            helper.setText(R.id.tv_base_money, String.format("%.2f", item.getSourceMoney()));
            helper.setTextColor(R.id.tv_base_money, MResUtil.getPingColor());
        }
        helper.setTextColor(R.id.tv_status, mContext.getResources().getColor(getStatusColor(item.getcStatus())));
    }

    private int getStatusColor(String status) {
        switch (status) {
            case "成功":
                return R.color.color_text_style1;
            case "失败":
                return R.color.color_T7;
            case "处理中":
                return R.color.color_K3;
            default:
                return R.color.color_text_style1;
        }
    }

}
